Skip to content

fix: plugin tooltip window size can adapt to content changes#357

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-adjustPluginToolTip
Aug 28, 2025
Merged

fix: plugin tooltip window size can adapt to content changes#357
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
yixinshark:fix-adjustPluginToolTip

Conversation

@yixinshark

@yixinshark yixinshark commented Aug 27, 2025

Copy link
Copy Markdown
Contributor

as title

Log: as title
Pms: BUG-290591

Summary by Sourcery

Detect content changes in TipsWidget and dynamically adjust its and its parent’s size when tooltip text or text list is updated.

Bug Fixes:

  • Prevent redundant updates by returning early if the new single-line or multi-line text matches the existing content.

Enhancements:

  • Recalculate widget dimensions based on updated text and call parentWidget()->adjustSize() to propagate size changes.

@sourcery-ai

sourcery-ai Bot commented Aug 27, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds early exits to skip redundant updates when tooltip content is unchanged and triggers parent widget size adjustments after resizing to ensure the tooltip window adapts to content changes.

Sequence diagram for tooltip content update and window resize

sequenceDiagram
participant App
participant TipsWidget
participant ParentWidget
App->>TipsWidget: setText(newText)
TipsWidget->>TipsWidget: Check if m_text == newText
alt Text unchanged
TipsWidget-->>App: Return (no update)
else Text changed
TipsWidget->>TipsWidget: Update m_text
TipsWidget->>TipsWidget: setFixedSize(...)
TipsWidget->>ParentWidget: adjustSize()
TipsWidget->>TipsWidget: update()
end
Loading

Class diagram for updated TipsWidget methods

classDiagram
class TipsWidget {
  - QString m_text
  - QStringList m_textList
  setText(QString text)
  setTextList(QStringList textList)
}
TipsWidget : setText() updated to skip redundant updates and adjust parent size
TipsWidget : setTextList() updated to skip redundant updates and adjust parent size
Loading

File-Level Changes

Change Details Files
Skip redundant updates when tooltip content hasn’t changed
  • In setText: compute simplified new text, compare with m_text, and return if identical
  • In setTextList: compare incoming textList with m_textList and return if identical
plugins/dde-dock/widgets/tipswidget.cpp
Ensure tooltip window adapts to updated content
  • After setFixedSize in setText: call parentWidget()->adjustSize() if a parent exists
  • After setFixedSize in setTextList: call parentWidget()->adjustSize() if a parent exists
plugins/dde-dock/widgets/tipswidget.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@yixinshark yixinshark force-pushed the fix-adjustPluginToolTip branch from 5387812 to 1625268 Compare August 27, 2025 08:12
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, yixinshark

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@yixinshark yixinshark force-pushed the fix-adjustPluginToolTip branch from 1625268 to 109f1e7 Compare August 28, 2025 09:28
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

这段代码是关于 TipsWidget 类的两个方法:setText 和 setTextList 的修改。我来对这段代码进行审查,并提出改进意见。

1. 语法逻辑

优点:

  • 代码结构清晰,逻辑易于理解
  • 使用了适当的 Qt 框架特性

改进建议:

  • 在 setText 方法中,先创建临时变量 newText,再进行比较,最后赋值,这种写法很好,避免了不必要的操作
  • setTextList 方法中也采用了类似的模式,先比较再赋值,这是良好的实践

2. 代码质量

优点:

  • 使用了条件判断来避免不必要的操作和更新
  • 代码注释清晰,特别是关于藏语字体绘制的注释很有价值

改进建议:

  • 可以考虑将 parentWidget()->adjustSize() 的逻辑提取为一个私有方法,以减少重复代码
  • 在 setText 和 setTextList 方法中,都添加了对 parentWidget() 的检查,这是好的防御性编程

3. 代码性能

优点:

  • 通过比较新旧文本内容,避免不必要的更新操作
  • 使用了 horizontalAdvance 和 boundingRect 来精确计算尺寸,提高了渲染效率

改进建议:

  • 在 setTextList 方法中,可以考虑先计算所有需要的尺寸,再一次性设置,而不是在循环中多次更新
  • 如果频繁调用这些方法,可以考虑添加缓存机制,避免重复计算

4. 代码安全

优点:

  • 对 parentWidget() 进行了空指针检查
  • 使用了 Qt 提供的安全方法来处理文本和尺寸计算

改进建议:

  • 可以考虑添加对输入参数的验证,例如检查 text 和 textList 是否为空
  • 在设置 m_text 和 m_textList 之前,可以添加对字符串长度的限制,防止过长的文本导致显示问题

具体改进建议代码示例:

void TipsWidget::setText(const QString &text)
{
    if (text.isEmpty()) {
        return;
    }
    
    QTextDocument document;
    document.setHtml(text);
    QString newText = document.toPlainText().simplified();
    
    if (m_text == newText) {
        return;
    }

    m_text = newText;
    
    // 调整尺寸
    adjustWidgetSize();
    
    update();
}

void TipsWidget::setTextList(const QStringList &textList)
{
    if (textList.isEmpty()) {
        return;
    }
    
    m_type = TipsWidget::MultiLine;
    
    if (textList == m_textList) {
        return;
    }
    
    m_textList = textList;
    
    // 调整尺寸
    adjustWidgetSize();
    
    update();
}

void TipsWidget::adjustWidgetSize()
{
    if (m_type == SingleLine) {
        setFixedSize(fontMetrics().horizontalAdvance(m_text), 
                    fontMetrics().boundingRect(m_text).height());
    } else {
        int width = 0;
        int height = 0;
        
        for (const QString &text : m_textList) {
            QSize textSize = fontMetrics().boundingRect(text).size();
            width = qMax(width, textSize.width());
            height += textSize.height();
        }
        
        setFixedSize(width, height);
    }
    
    if (parentWidget()) {
        parentWidget()->adjustSize();
    }
}

这个改进版本提取了调整尺寸的逻辑到单独的方法中,减少了重复代码,并添加了对输入参数的验证。同时,保持了原有的性能优化和安全检查。

@yixinshark

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Aug 28, 2025

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 278fb90 into linuxdeepin:master Aug 28, 2025
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants